package io.renren.modules.live.service.impl;

import io.renren.modules.live.vo.PropListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.live.dao.FanwePropDao;
import io.renren.modules.live.entity.FanwePropEntity;
import io.renren.modules.live.service.FanwePropService;


@Service("fanwePropService")
public class FanwePropServiceImpl extends ServiceImpl<FanwePropDao, FanwePropEntity> implements FanwePropService {
    @Autowired(required = false)
    FanwePropDao fanwePropDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FanwePropEntity> page = this.page(
                new Query<FanwePropEntity>().getPage(params),
                new QueryWrapper<FanwePropEntity>()
        );

        return new PageUtils(page);
    }
    /**
     * 查询礼物列表集合
     * @param propListVo
     * @return
     */
    @Override
    public Map<String, Object> selectPropLise(PropListVo propListVo) throws Exception{
        Map<String, Object> map=new HashMap();
        propListVo.setPageIndex((propListVo.getPageIndex()-1)*propListVo.getPageSize());
        List<FanwePropEntity> fanwePropEntities = fanwePropDao.selectPropLise(propListVo);
        Integer integer = fanwePropDao.selectPropLiseCount(propListVo);
        map.put("fanwePropEntities",fanwePropEntities);
        map.put("count",integer);
        return map;
    }

    /**
     * 新建或更新礼物
     * @param fanwePropEntity
     * @return
     * @throws Exception
     */
    @Override
    public Integer creatAndUpdateProp(FanwePropEntity fanwePropEntity) throws Exception {
        Integer integer=0;
        if(fanwePropEntity.getId()==null){
            integer = fanwePropDao.creatProp(fanwePropEntity);
        }else{
            integer =fanwePropDao.updateProp(fanwePropEntity);
        }
        return integer;
    }

    /**
     * 修改礼物信息状态
     * @param isEffect
     * @return
     * @throws Exception
     */
    @Override
    public Integer updatePropIsEffect(String isEffect,String id) throws Exception {
        Integer integer = fanwePropDao.updatePropIsEffect(isEffect,id);
        return integer;
    }
    /**
     * 通过id查询礼物信息
     * @param id
     * @return
     */
    @Override
    public FanwePropEntity selectProp(String id) {
        FanwePropEntity fanwePropEntity = fanwePropDao.selectProp(id);
        return fanwePropEntity;
    }

}